<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello React!</title>
<!-- react核心库 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<!-- 支持react操作DOM -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
<!-- 引入Babel，用于将JSX转换为JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<!-- prop-types -->
<script src="https://unpkg.com/prop-types@15.7.2/prop-types.js"></script>

</head>
<body>

<div id="test1"></div>
<div id="test2"></div>
<div id="test3"></div>


<script type="text/babel"> 
    class Person extends React.Component{
        render(){
            //props只只读的
            const {name, age, sex} = this.props;
            return(
                <ul>
                    <li>姓名:{name}</li>
                    <li>年龄:{age+1}</li>
                    <li>性别:{sex}</li>
                </ul>
            )
        }
    }
    //对标签属性进行类型，必要性的限制
    Person.propTypes = {
        name: PropTypes.string.isRequired,
        age: PropTypes.number,
        sex: PropTypes.string,
        speak:PropTypes.func,
    };

    //指定默认标签属性
    Person.defaultProps = {
        sex:'Male',
    }

    function speak(){
        console.log('hello')
    }
 

    ReactDOM.render(<Person name = "Jerry" age = "19" sex = 'Male' abc={speak} />,document.getElementById('test1'))
    ReactDOM.render(<Person name = "Cherry" age = "19" sex = 'Female' />,document.getElementById('test2'))
    
    //在react中babel+react可以在标签中展开对象
    const p = {name:100,age:19,sex:'Female'}
    ReactDOM.render(<Person {...p} />,document.getElementById('test3'))

</script>

</body>
</html>